package subject_set.offer100;

/**
 * @author haomin
 * @date 2022/10/20 15:49
 **/
public class Offer39 {
    class Solution {
        public int majorityElement(int[] nums) {
            int target = 0, count = 0;
            for(int i : nums){
                if(count == 0){
                    target = i;
                    count++;
                }else if(target == i){
                    count++;
                }else if(target != i){
                    count--;
                }
            }
            return target;
        }
    }
}